<?php 
class CUserController extends CController{

	protected $m_arrobjUsers;
	protected $m_objUser;
	
	function __construct() {
		parent::__construct();
		return true;
	}
	
	function create() {
		parent::create();
	}
	
	function initialize() {
		parent::initialize();
	}
	
	function execute() {		
		
		switch( $this->m_strAction ) {
			
			case NULL:			
			case 'list':
				$this->handleViewUserList();
				break;
				
			case 'add':
				$this->handleAddUser();
				break;
							
			case 'edit':
				$this->handleEditUser();
				break;
			
			case 'view':
				$this->handleViewUser();
				break;
				
			default:
				// Empty default case
				
		}
	}

	/*************************************
	********** HANDLE FUNCTIONS **********
	*************************************/
		
	function handleViewUserList() {
		$this->m_arrobjUsers = CUsers::fetchUsersByUserTypeId( CUser::ADMIN_USER, $this->m_objDatabase );	
		$this->displayUserList();
	}
	
	function handleAddUser() {
		$this->displayAddUser();
	}
	
	function handleEditUser() {
		$intUserId = $_REQUEST['id'];
		$this->m_objUser = CUsers::fetchUserById( $intUserId, $this->m_objDatabase );
		$this->displayEditUser();
	}

	function handleViewUser() {
		$intUserId = $_REQUEST['id'];
		$this->m_objUser = CUsers::fetchUserById( $intUserId, $this->m_objDatabase );
	
		$this->displayViewUser();
	}
	
	/**************************************
	********** DISPLAY FUNCTIONS **********
	**************************************/		
	
	function displayUserList() {
		parent::display();
		
		
		$this->m_objSmarty->assign( 'users', $this->m_arrobjUsers );
		$this->m_objSmarty->assign( 'leftadminmenu', 'user_list' );
		$this->m_objSmarty->display( TEMPLATE_DIR_PATH . '/admin/user/view_user_list.tpl');
	}
	
	function displayEditUser() {
		parent::display();

		$this->m_objSmarty->assign( 'user', $this->m_objUser );
		$this->m_objSmarty->assign( 'leftadminmenu', 'user_list' );
		$this->m_objSmarty->display( TEMPLATE_DIR_PATH . '/admin/user/view_edit_user.tpl');

	}
	
	function displayViewUser() {
		parent::display();

		$this->m_objSmarty->assign( 'user', $this->m_objUser );
		$this->m_objSmarty->assign( 'leftadminmenu', 'user_list' );
		$this->m_objSmarty->display( TEMPLATE_DIR_PATH . '/admin/user/view_user.tpl');

	}

}
?>